<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<style type="text/css">
#sql2{
width:95%;
height:50%
}
</style>

<script type="text/javascript" src="/static/commons/admin.js"></script>
<script type="text/javascript">
function createCode(){
	if(!$('#sql2').val()){
		showErrorMessage('请输入sql语句');
		return;
	}
	
	var form = {};
	form.domainModule = $('#sql2_domainModule').val() ? $('#sql2_domainModule').val() : $('#sql2_domainModule').attr('placeholder');
	form.mapperModule = $('#sql2_mapperModule').val() ? $('#sql2_mapperModule').val() : $('#sql2_mapperModule').attr('placeholder');
	form.sql = $('#sql2').val();
	
	$.ajax({
		type : "post",
		url : 'code/sql/code.json',
		data : form,
		success : function(data) {
			$('#sql2_result').empty();
			if(data.code == 0){
				$('#sql2_result').append(new Date() + "</br>");
				$('#sql2_result').append('<strong>mappers/' + data.mybatisXmlName + '</strong>');
				$('#sql2_result').append('&nbsp;&nbsp;<a target="_blank" href="' + data.mybatisXmlPreviewUrl + '">查看</a>&nbsp;&nbsp;<a target="_blank" href="' + data.mybatisXmlDownloadUrl + '">下载</a></br>');

				var dir = 'com/joinway/' + form.mapperModule + '/mapper/';
				$('#sql2_result').append('<strong>' + dir + data.daoName + '</strong>');
				$('#sql2_result').append('&nbsp;&nbsp;<a target="_blank" href="' + data.daoPreviewUrl + '">查看</a>&nbsp;&nbsp;<a target="_blank" href="' + data.daoDownloadUrl + '">下载</a></br>');

				dir = 'com/joinway/' + form.mapperModule + '/repository/';
				$('#sql2_result').append('<strong>' + dir + data.daoRepositoryName + '</strong>');
				$('#sql2_result').append('&nbsp;&nbsp;<a target="_blank" href="' + data.daoRepositoryPreviewUrl + '">查看</a>&nbsp;&nbsp;<a target="_blank" href="' + data.daoRepositoryDownloadUrl + '">下载</a></br>');
			}else{
				handleError(data.code);
			}
		},
		error: function(){
			showErrorMessage('生成失败');
		}
	});
}
</script>
<h1>根据SQL(查询或DDL语句)生成代码</h1>

<div>
<table>
	<tr>
		<td style="width:50%">域对象所在模块的名字<input id="sql2_domainModule" type="text" placeholder="common"/></td>
		<td>mybatis类所在模块的名字<input id="sql2_mapperModule" type="text" placeholder="mobile"/></td>
	</tr>
</table>
</div>

<div>
<ul>
<li>如果是DDL必须只有一个自增主键</li>
</ul>
</div>
<div id="parseSql">
</div>
<textarea id="sql2"></textarea><br/>
<!-- <input type="button" value="解析" onclick="parse();"/> -->
<input type="button" value="生成" onclick="createCode();"/>
<input type="button" value="清空" onclick="clearInput('#sql2');$('#sql2_result').empty();$('#parseSql').empty();"/>

<div>
<ul>
<!-- <li>请参�??<strong>com.joinway.appx.repository.TableRepository</strong>查看更多单表查询api</li>
<li>自动生成的mybatis配置文件仅供参�?�用，请根据�??要�?�当修改</li>
<li>自动生成�?? dao和respsitory仅供参�?�用，请根据�??要�?�当修改</li> -->
</ul>
</div>
<div id="sql2_result">
</div>
